<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx 性能优化完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            background: rgba(255, 255, 255, 0.95);
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            border-color: rgba(102, 126, 234, 0.3);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            padding: 1.5rem;
            overflow-x: auto;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            position: relative;
        }
        
        .code-block::before {
            content: 'nginx';
            position: absolute;
            top: 10px;
            right: 15px;
            font-size: 0.75rem;
            color: #666;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        
        .section-title {
            position: relative;
            padding-left: 1.5rem;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 80%;
            background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            color: white;
            font-size: 1.5rem;
            margin-bottom: 1rem;
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            border-radius: 8px;
            margin: 1.5rem 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                <i class="fas fa-server mr-4"></i>Nginx 性能优化完全指南
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">
                掌握专业技巧，让你的 Web 服务器性能飞跃
            </p>
            <div class="flex justify-center space-x-8 text-lg">
                <div class="flex items-center">
                    <i class="fas fa-rocket mr-2"></i>
                    <span>高性能</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-shield-alt mr-2"></i>
                    <span>高可用</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-chart-line mr-2"></i>
                    <span>可扩展</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-7xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="card-hover rounded-2xl p-8 mb-8 animate-fadeInUp">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">通</span>过调整配置参数、优化静态文件处理、提高反向代理效率、选择适当的负载均衡策略，并使用监控工具来跟踪和优化性能，可以有效地提升 Nginx 的整体性能。每个优化策略应根据具体的应用场景和需求进行调整和实施。
            </p>
        </div>

        <!-- Performance Optimization Mindmap -->
        <div class="card-hover rounded-2xl p-8 mb-12 animate-fadeInUp">
            <h2 class="text-3xl font-bold mb-6 text-center text-gray-800">
                <i class="fas fa-sitemap mr-3 text-purple-600"></i>性能优化架构图
            </h2>
            <div class="mermaid">
                graph TD
                    A[Nginx 性能优化] --> B[配置优化]
                    A --> C[静态文件处理]
                    A --> D[反向代理优化]
                    A --> E[负载均衡]
                    A --> F[监控调优]
                    
                    B --> B1[工作进程数]
                    B --> B2[连接数调整]
                    B --> B3[启用缓存]
                    B --> B4[启用压缩]
                    
                    C --> C1[静态缓存]
                    C --> C2[高效传输]
                    
                    D --> D1[超时设置]
                    D --> D2[速率限制]
                    
                    E --> E1[算法选择]
                    E --> E2[健康检查]
                    
                    F --> F1[性能监控]
                    F --> F2[日志分析]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                    style E fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                    style F fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Section 1: 优化 Nginx 配置 -->
        <section class="mb-12 animate-fadeInUp">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                1. 优化 Nginx 配置
            </h2>
            
            <div class="grid md:grid-cols-2 gap-6">
                <!-- 1.1 调整工作进程数 -->
                <div class="card-hover rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-microchip"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">1.1 调整工作进程数</h3>
                    <p class="text-gray-600 mb-4">
                        <strong>配置：</strong><code class="bg-gray-100 px-2 py-1 rounded">worker_processes</code> 指令
                    </p>
                    <p class="text-gray-600 mb-4">
                        <strong>说明：</strong>设置为与服务器 CPU 核心数相等的值可以提高性能。Nginx 可以并行处理多个请求，提高吞吐量。
                    </p>
                    <div class="code-block">
                        <pre><code>worker_processes auto;</code></pre>
                    </div>
                </div>

                <!-- 1.2 调整工作连接数 -->
                <div class="card-hover rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-network-wired"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">1.2 调整工作连接数</h3>
                    <p class="text-gray-600 mb-4">
                        <strong>配置：</strong><code class="bg-gray-100 px-2 py-1 rounded">worker_connections</code> 指令
                    </p>
                    <p class="text-gray-600 mb-4">
                        <strong>说明：</strong>增加每个工作进程的最大连接数，以处理更多的并发连接。注意，这个值与服务器的资源（如内存）有关。
                    </p>
                    <div class="code-block">
                        <pre><code>events {
    worker_connections 1024;
}</code></pre>
                    </div>
                </div>

                <!-- 1.3 启用缓存 -->
                <div class="card-hover rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-database"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">1.3 启用缓存</h3>
                    <p class="text-gray-600 mb-4">
                        <strong>配置：</strong><code class="bg-gray-100 px-2 py-1 rounded">proxy_cache</code> 指令
                    </p>
                    <p class="text-gray-600 mb-4">
                        <strong>说明：</strong>使用缓存可以减少后端服务器的负载，提高响应速度。配置缓存策略和大小以满足需求。
                    </p>
                    <div class="code-block">
                        <pre><code>http {
    proxy_cache_path /data/nginx/cache keys_zone=my_cache:10m max_size=1g;
    server {
        location / {
            proxy_cache my_cache;
            proxy_pass http://backend;
        }
    }
}</code></pre>
                    </div>
                </div>

                <!-- 1.4 使用压缩 -->
                <div class="card-hover rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-compress"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">1.4 使用压缩</h3>
                    <p class="text-gray-600 mb-4">
                        <strong>配置：</strong><code class="bg-gray-100 px-2 py-1 rounded">gzip</code> 指令
                    </p>
                    <p class="text-gray-600 mb-4">
                        <strong>说明：</strong>启用 Gzip 压缩可以减少数据传输量，提高传输效率。
                    </p>
                    <div class="code-block">
                        <pre><code>http {
    gzip on;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 2: 优化静态文件处理 -->
        <section class="mb-12 animate-fadeInUp">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                2. 优化静态文件处理
            </h2>
            
            <div class="grid md:grid-cols-2 gap-6">
                <!-- 2.1 启用静态文件缓存 -->
                <div class="card-hover rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-clock"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">2.1 启用静态文件缓存</h3>
                    <p class="text-gray-600 mb-4">
                        <strong>配置：</strong><code class="bg-gray-100 px-2 py-1 rounded">expires</code> 指令
                    </p>
                    <p class="text-gray-600 mb-4">
                        <strong>说明：</strong>设置静态文件的过期时间，减少重复请求的频率